package com.flk.oauth.controller;

import com.flk.oauth.entity.OauthUser;
import com.flk.oauth.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

/**
 * @author xxwy
 * on 2018/10/16 0016
 */
@RestController
public class BaseUserController {

    @Autowired
    RedisTemplate  redisTemplate;

    @RequestMapping("/user/info")
    public ResponseEntity getUserInfo(@AuthenticationPrincipal UserDetails userDetails) {
        return ResponseEntity.ok(userDetails);
    }

    @RequestMapping("/user/authority")
    public ResponseEntity getUserAuthority() {
        Collection<? extends GrantedAuthority> currentUserAuthority = SecurityUtils.getCurrentUserAuthority();
        return ResponseEntity.ok(currentUserAuthority);
    }



}
